﻿using System;

namespace Goway.IniConifigHelper
{
    /// <summary>
    /// 配置文件管理类
    /// </summary>
    public static class ConfigManger
    {
        //private readonly string _iniPath = @"~\Config\Config.ini";
        private static readonly string IniPath = AppDomain.CurrentDomain.BaseDirectory + @"\Config\Config.ini";
        private static readonly IniFileReadWite _ini = new IniFileReadWite(IniPath);

        private static string _systemTitle;
        private static string _apiUrl;

        private static string _roadGateMsmq;
        private static string _vehicleStatusMsmq;
        private static string _carStateMsmq;
        private static string _picPath;
        private static string _oldpicPath;
        private static string _newpicPath;
        private static string _time;
        private static string _TimeBxoBar;
        private static string _runTime;
        private static bool _isDebug;
        private static string _vehicleStateMsmq;
        private static string _carStateChangeTime;
        private static string _carStatesTime;
        private static string _dbType;
        private static string _sleepTime;
        internal static string _Description;
        internal static string _ServiceName;
        private static string _LNGplant;
        private static string _YtHapiUrl;
        private static string _idsData;
        private static string _accessKeyId;
        private static string _accessKeySecret;
        private static string _YthaccessKeyId;
        private static string _YthaccessKeySecret;
        private static string _savaDay;
        private static string _isToSendYth;
        private static string _com;
        private static string _baudRate;
        private static string _dataBits;
        private static string _Parity;
        private static string _StopBits;
        private static string _PLCDB1;
        private static string _PLCDB2;
        private static string _XTDB;
        private static string _Print1Ip;
        private static string _Print2Ip;
        private static string _IPUP;
        private static string _IPDOWN;
        private static string _IPLEFT;
        private static string _IPRIGHT;
 
        private static bool _RunPLC1;
        private static bool _RunPLC2;
        private static bool _RunXT;
        public static string IPRIGHT
        {
            get
            {
                if (string.IsNullOrEmpty(_IPRIGHT))
                {
                    _IPRIGHT = _ini.ReadIniValue("System", "IPRIGHT").Trim();
                }

                return _IPRIGHT;
            }
        }
        public static string IPUP
        {

            get
            {
                if (string.IsNullOrEmpty(_IPUP))
                {
                    _IPUP = _ini.ReadIniValue("System", "IPUP").Trim();
                }
                return _IPUP;
            }
        }
        public static string IPDOWN
        {

            get
            {
                if (string.IsNullOrEmpty(_IPDOWN))
                {
                    _IPDOWN = _ini.ReadIniValue("System", "IPDOWN").Trim();
                }
                return _IPDOWN;
            }
        }
        public static string IPLEFT
        {

            get
            {
                if (string.IsNullOrEmpty(_IPLEFT))
                {
                    _IPLEFT = _ini.ReadIniValue("System", "IPLEFT").Trim();
                }
                return _IPLEFT;
            }
        }
        public static bool IsDebug
        {
            get
            {
                _isDebug = _ini.ReadIniValue("System", "IsDebug").ToLower() == "true";
                return _isDebug;
            }
        }

        /// <summary>
        /// MySQL数据连接字符串
        /// </summary>
        public static string MySQL
        {
            get
            {
                return StringValue("System", "MySQL", null);
            }
        }

        /// <summary>
        /// 获取字符串值
        /// </summary>
        /// <param name="section">区域</param>
        /// <param name="key">参数键</param>
        /// <param name="value">默认值</param>
        /// <returns></returns>
        public static string StringValue(string section, string key, string value)
        {
            try
            {
                string result = _ini.ReadIniValue(section, key);
                if (result != null && result.Trim().Length > 0) value = result;
            }
            catch { }
            return value;
        }
        /// <summary>
        /// 获取Int值
        /// </summary>
        /// <param name="section">区域</param>
        /// <param name="key">参数键</param>
        /// <param name="value">默认值</param>
        /// <returns></returns>
        public static int IntValue(string section, string key, int value)
        {
            try
            {
                string result = _ini.ReadIniValue(section, key);
                value = Convert.ToInt32(result);
            }
            catch { }
            return value;
        }
        /// <summary>
        /// 获取Bool值
        /// </summary>
        /// <param name="section">区域</param>
        /// <param name="key">参数键</param>
        /// <param name="value">默认值</param>
        /// <returns></returns>
        public static bool BoolValue(string section, string key, bool value)
        {
            try
            {
                string result = _ini.ReadIniValue(section, key);
                if (result != null && result == "1") result = "true";
                else if (result != null && result == "0") result = "false";
                value = Convert.ToBoolean(result);
            }
            catch { }
            return value;
        }

        public static double doubleValue(string section, string key, double value)
        {
            try
            {
                string result = _ini.ReadIniValue(section, key);
                value = Convert.ToDouble(result);
            }
            catch { }
            return value;
        }

        public static string SqlServer
        {
            get
            {
                return StringValue("System", "SqlServer", null);
            }
        }

        public static bool RunPLC1
        {
            get
            {
                _RunPLC1 = _ini.ReadIniValue("System", "RunPLC1").ToLower() == "true";
                return _RunPLC1;
            }
        }

        public static bool RunXT
        {
            get
            {
                _RunXT = _ini.ReadIniValue("System", "RunXT").ToLower() == "true";
                return _RunXT;
            }
        }
        public static bool RunPLC2
        {
            get
            {
                _RunPLC2 = _ini.ReadIniValue("System", "RunPLC2").ToLower() == "true";
                return _RunPLC2;
            }
        }


        public static string baudRate
        {

            get
            {
                if (string.IsNullOrEmpty(_baudRate))
                {
                    _baudRate = _ini.ReadIniValue("System", "baudRate").Trim();
                }
                return _baudRate;
            }
        }

        public static string Print1Ip
        {

            get
            {
                if (string.IsNullOrEmpty(_Print1Ip))
                {
                    _Print1Ip = _ini.ReadIniValue("System", "Print1Ip").Trim();
                }
                return _Print1Ip;
            }
        }
        public static string Print2Ip
        {

            get
            {
                if (string.IsNullOrEmpty(_Print2Ip))
                {
                    _Print2Ip = _ini.ReadIniValue("System", "Print2Ip").Trim();
                }
                return _Print2Ip;
            }
        }


        public static string dataBits
        {

            get
            {
                if (string.IsNullOrEmpty(_dataBits))
                {
                    _dataBits = _ini.ReadIniValue("System", "dataBits").Trim();
                }
                return _dataBits;
            }
        }

        public static string Parity
        {

            get
            {
                if (string.IsNullOrEmpty(_Parity))
                {
                    _Parity = _ini.ReadIniValue("System", "Parity").Trim();
                }
                return _Parity;
            }
        }

        public static string StopBits
        {

            get
            {
                if (string.IsNullOrEmpty(_StopBits))
                {
                    _StopBits = _ini.ReadIniValue("System", "StopBits").Trim();
                }
                return _StopBits;
            }
        } 
        
        public static string PLCDB1
        {

            get
            {
                if (string.IsNullOrEmpty(_PLCDB1))
                {
                    _PLCDB1 = _ini.ReadIniValue("System", "PLCDB1").Trim();
                }
                return _PLCDB1;
            }
        } 
        
        public static string PLCDB2
        {

            get
            {
                if (string.IsNullOrEmpty(_PLCDB2))
                {
                    _PLCDB2 = _ini.ReadIniValue("System", "PLCDB2").Trim();
                }
                return _PLCDB2;
            }
        }
        public static string XTDB
        {

            get
            {
                if (string.IsNullOrEmpty(_XTDB))
                {
                    _XTDB = _ini.ReadIniValue("System", "XTDB").Trim();
                }
                return _XTDB;
            }
        }

        public static string Com
        {

            get
            {
                if (string.IsNullOrEmpty(_com))
                {
                    _com = _ini.ReadIniValue("System", "com").Trim();
                }
                return _com;
            }
        }

        public static string savaDay
        {

            get
            {
                if (string.IsNullOrEmpty(_savaDay))
                {
                    _savaDay = _ini.ReadIniValue("System", "savaDay").Trim();
                }
                return _savaDay;
            }
        }
        public static string isToSendYth
        {

            get
            {
                if (string.IsNullOrEmpty(_isToSendYth))
                {
                    _isToSendYth = _ini.ReadIniValue("System", "isToSendYth").Trim();
                }
                return _isToSendYth;
            }
        }

        public static string SleepTime
        {
            get
            {
                if (string.IsNullOrEmpty(_sleepTime))
                {
                    _sleepTime = _ini.ReadIniValue("System", "SleepTime").Trim();
                }
                return _sleepTime;
            }
        }




        public static string LngPlant
        {
            get
            {
                if (string.IsNullOrEmpty(_LNGplant))
                {
                    _LNGplant = _ini.ReadIniValue("System", "LNGplant").Trim();
                }
                return _LNGplant;
            }
        }
        public static string YtHapiUrl
        {
            get
            {
                if (string.IsNullOrEmpty(_YtHapiUrl))
                {
                    _YtHapiUrl = _ini.ReadIniValue("System", "YtHapiUrl").Trim();
                }
                return _YtHapiUrl;
            }
        }

        public static string idsData
        {
            get
            {
                if (string.IsNullOrEmpty(_idsData))
                {
                    _idsData = _ini.ReadIniValue("System", "idsData").Trim();
                }
                return _idsData;
            }
        }

        public static string runTime
        {
            get
            {
                if (string.IsNullOrEmpty(_runTime))
                {
                    _runTime = _ini.ReadIniValue("System", "runTime").Trim();
                }
                return _runTime;
            }
        }
        public static string Time
        {
            get
            {
                if (string.IsNullOrEmpty(_time))
                {
                    _time = _ini.ReadIniValue("System", "Time").Trim();
                }
                return _time;
            }
        }
        public static string TimeBxoBar
        {
            get
            {
                if (string.IsNullOrEmpty(_TimeBxoBar))
                {
                    _TimeBxoBar = _ini.ReadIniValue("System", "TimeBxoBar").Trim();
                }
                return _TimeBxoBar;
            }
        }

        public static string dbType
        {
            get
            {
                if (string.IsNullOrEmpty(_dbType))
                {
                    _dbType = _ini.ReadIniValue("System", "dbType").Trim();
                }
                return _dbType;
            }
        }
        public static string SystemTitle
        {
            get
            {
                if (string.IsNullOrEmpty(_systemTitle))
                {
                    _systemTitle = _ini.ReadIniValue("System", "SystemTitle").Trim();
                }
                return _systemTitle;
            }
        }

        public static string Description
        {
            get
            {
                if (string.IsNullOrEmpty(_Description))
                {
                    _Description = _ini.ReadIniValue("System", "Description").Trim();
                }
                return _Description;
            }
        }

        
        public static string ServiceName
        {
            get
            {
                if (string.IsNullOrEmpty(_ServiceName))
                {
                    _ServiceName = _ini.ReadIniValue("System", "ServiceName").Trim();
                }
                return _ServiceName;
            }
        }
        public static string CarStatesTime
        {
            get
            {
                if (string.IsNullOrEmpty(_carStatesTime))
                {
                    _carStatesTime = _ini.ReadIniValue("System", "CarStatesTime").Trim();
                }
                return _carStatesTime;
            }
        }

        public static string CarStateChangeTime
        {
            get
            {
                if (string.IsNullOrEmpty(_carStateChangeTime))
                {
                    _carStateChangeTime = _ini.ReadIniValue("System", "CarStateChangeTime").Trim();
                }
                return _carStateChangeTime;
            }
        }

        public static string ApiUrl
        {
            get
            {
                if (string.IsNullOrEmpty(_apiUrl))
                {
                    _apiUrl = _ini.ReadIniValue("System", "apiUrl").Trim();
                }
                return _apiUrl;
            }
        }

        public static string RoadGateMsmq
        {
            get
            {
                if (string.IsNullOrEmpty(_roadGateMsmq))
                {
                    _roadGateMsmq = _ini.ReadIniValue("MQ", "roadGateMsmq").Trim().ToLower();
                }
                return _roadGateMsmq;
            }
        }

        public static string VehicleStatusMsmq
        {
            get
            {
                if (string.IsNullOrEmpty(_vehicleStatusMsmq))
                {
                    _vehicleStatusMsmq = _ini.ReadIniValue("MQ", "vehicleStatusMsmq").Trim().ToLower();
                }
                return _vehicleStatusMsmq;
            }
        }


        public static string CarStateMsmq
        {
            get
            {
                if (string.IsNullOrEmpty(_carStateMsmq))
                {
                    _carStateMsmq = _ini.ReadIniValue("MQ", "carStateMsmq").Trim().ToLower();
                }
                return _carStateMsmq;
            }
        }

        public static string VehicleStateMsmq
        {
            get
            {
                if (string.IsNullOrEmpty(_vehicleStateMsmq))
                {
                    _vehicleStateMsmq = _ini.ReadIniValue("MQ", "vehicleStateMsmq").Trim().ToLower();
                }
                return _vehicleStateMsmq;
            }
        }

        public static string PicPath
        {
            get
            {
                if (string.IsNullOrEmpty(_picPath))
                {
                    _picPath = _ini.ReadIniValue("Camera", "picPath").Trim();
                }
                return _picPath;
            }
        }
        public static string NewPicPath
        {
            get
            {
                if (string.IsNullOrEmpty(_newpicPath))
                {
                    _newpicPath = _ini.ReadIniValue("Camera", "newPicPath").Trim();
                }
                return _newpicPath;
            }
        }
        public static string OldPicPath
        {
            get
            {
                if (string.IsNullOrEmpty(_oldpicPath))
                {
                    _oldpicPath = _ini.ReadIniValue("Camera", "oldPicPath").Trim();
                }
                return _oldpicPath;
            }
        }



        public static string accessKeyId
        {
            get
            {
                if (string.IsNullOrEmpty(_accessKeyId))
                {
                    _accessKeyId = _ini.ReadIniValue("System", "accessKeyId").Trim();
                }
                return _accessKeyId;
            }
        }

        public static string accessKeySecret
        {
            get
            {
                if (string.IsNullOrEmpty(_accessKeySecret))
                {
                    _accessKeySecret = _ini.ReadIniValue("System", "accessKeySecret").Trim();
                }
                return _accessKeySecret;
            }
        }


        public static string YthaccessKeyId
        {
            get
            {
                if (string.IsNullOrEmpty(_YthaccessKeyId))
                {
                    _YthaccessKeyId = _ini.ReadIniValue("System", "YthaccessKeyId").Trim();
                }
                return _YthaccessKeyId;
            }
        }

        public static string YthaccessKeySecret
        {
            get
            {
                if (string.IsNullOrEmpty(_YthaccessKeySecret))
                {
                    _YthaccessKeySecret = _ini.ReadIniValue("System", "YthaccessKeySecret").Trim();
                }
                return _YthaccessKeySecret;
            }
        }

        public static string UserName { get; set; }
        public static string Surl { get; set; }
        public static string PassWord { get; set; }
        public static string EnterpriseId { get; set; }
        public static string OrgID
        {
            get
            {
                if (string.IsNullOrEmpty(_OrgID))
                {
                    _OrgID = _ini.ReadIniValue("System", "OrgID").Trim();
                }
                return _OrgID;
            }
        }
        private static string _OrgID;



        /// <summary>
        /// 系统皮肤
        /// </summary>
        public static int LeftSleepTime
        {
            get
            {
                return IntValue("AutoTesting", "LeftSleepTime", 900);
            }
            set
            {
                _ini.WriteIniValue("AutoTesting", "LeftSleepTime", value + "");
            }
        }

        public static int ReghitSleepTime
        {
            get
            {
                return IntValue("AutoTesting", "ReghitSleepTime", 1000);
            }
            set
            {
                _ini.WriteIniValue("AutoTesting", "ReghitSleepTime", value + "");
            }
        }

        public static double LR_D
        {
            get
            {
                return doubleValue("AutoTesting", "LR_D", -3.5);
            }
            set
            {
                _ini.WriteIniValue("AutoTesting", "LR_D", value + "");
            }
        }
        public static double UD_D
        {
            get
            {
                return doubleValue("AutoTesting", "UD_D", 3.1);
            }
            set
            {
                _ini.WriteIniValue("AutoTesting", "UD_D", value + "");
            }
        }


        public static double LR_Lenth
        {
            get
            {
                return doubleValue("AutoTesting", "LR_Lenth", 3.1);
            }
            set
            {
                _ini.WriteIniValue("AutoTesting", "LR_Lenth", value + "");
            }
        }

        public static double UD_Lenth
        {
            get
            {
                return doubleValue("AutoTesting", "UD_Lenth", 3.1);
            }
            set
            {
                _ini.WriteIniValue("AutoTesting", "UD_Lenth", value + "");
            }
        } 
        public static int BinBarLength
        {
            get
            {
                return IntValue("AutoTesting", "BinBarLength",5);
            }
            set
            {
                _ini.WriteIniValue("AutoTesting", "BinBarLength", value + "");
            }
        }


        public static double LA
        {
            get
            {
                return doubleValue("AutoTesting", "LA", 0);
            }
            set
            {
                _ini.WriteIniValue("AutoTesting", "LA", value + "");
            }
        }

        public static double RA
        {
            get
            {
                return doubleValue("AutoTesting", "RA", 0);
            }
            set
            {
                _ini.WriteIniValue("AutoTesting", "RA", value + "");
            }
        }

        public static double UA
        {
            get
            {
                return doubleValue("AutoTesting", "UA", 0);
            }
            set
            {
                _ini.WriteIniValue("AutoTesting", "UA", value + "");
            }
        }

        public static double DA
        {
            get
            {
                return doubleValue("AutoTesting", "DA", 0);
            }
            set
            {
                _ini.WriteIniValue("AutoTesting", "DA", value + "");
            }
        }


        public static double Fa
        {
            get
            {
                return doubleValue("AutoTesting", "Fa", 0);
            }
            set
            {
                _ini.WriteIniValue("AutoTesting", "Fa", value + "");
            }
        }

        public static double Ba
        {
            get
            {
                return doubleValue("AutoTesting", "Ba", 0);
            }
            set
            {
                _ini.WriteIniValue("AutoTesting", "Ba", value + "");
            }
        }

        public static double Fb
        {
            get
            {
                return doubleValue("AutoTesting", "Fb", 0);
            }
            set
            {
                _ini.WriteIniValue("AutoTesting", "Fb", value + "");
            }
        }

        public static double Bb
        {
            get
            {
                return doubleValue("AutoTesting", "Bb", 0);
            }
            set
            {
                _ini.WriteIniValue("AutoTesting", "Bb", value + "");
            }
        }


        public static int SaveDay
        {
            get
            {
                return IntValue("AutoTesting", "SaveDay",7);
            }
            set
            {
                _ini.WriteIniValue("AutoTesting", "SaveDay", value + "");
            }
        }


        public static int DeductionLength
        {
            get
            {
                return IntValue("AutoTesting", "DeductionLength", 3);
            }
            set
            {
                _ini.WriteIniValue("AutoTesting", "DeductionLength", value + "");
            }
        }

        public static int DLength
        {
            get
            {
                return IntValue("AutoTesting", "DeductionLength", 3);
            }
            set
            {
                _ini.WriteIniValue("AutoTesting", "DeductionLength", value + "");
            }
        }


        public static double HLengMax
        {
            get
            {
                return doubleValue("AutoTesting", "HLengMax", 0.01);
            }
            set
            {
                _ini.WriteIniValue("AutoTesting", "HLengMax", value + "");
            }
        }

        public static double HLengMin
        {
            get
            {
                return doubleValue("AutoTesting", "HLengMin", 0.01);
            }
            set
            {
                _ini.WriteIniValue("AutoTesting", "HLengMin", value + "");
            }
        }

    }
}